package taskit.datastructures;

import java.io.Serializable;
import java.util.LinkedList;

import org.codehaus.jackson.annotate.JsonTypeInfo;

// @author A0087072A
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
public class Task implements Serializable, Completable {
	private static final long serialVersionUID = 1L;
	private String name;
	private Date completeDate;
	private boolean complete = false;
	private String memo;
	private boolean lastAdded = false;
	private LinkedList<String> tags;

	// class constructors

	public Task() {
	}

	public Task(String name) {
		this.name = name;
	}
	
	public Task(String name, LinkedList<String> tags) {
		this.name = name;
		this.tags = tags;
	}
	
	public Task(String name, Date completeDate, boolean complete, String memo, boolean lastAdded) {
		this.name = name;
		this.completeDate = completeDate;
		this.complete = complete;
		this.memo = memo;
		this.lastAdded = lastAdded;
	}

	public String getName() {
		return name;
	}
	
	public boolean isLastAdded() {
		return lastAdded;
	}

	/**
	 * setTaskName sets the taskName variable
	 * @param newName the new name to be set
	 * @return 0 on success, 1 on failure
	 */
	public int setName(String newName) {
		try {
			this.name = newName;
		} catch (Exception anyEx) {
			anyEx.printStackTrace();
			return 1;
		}
		return 0;
	}
	
	@Override
	public boolean isComplete() {
		return complete;
	}
	
	@Override
	public void toggleComplete() {
		if (completeDate == null) {
			completeDate = Date.currentDate();
			complete = true;
		} else {
			completeDate = null;
			complete = false;
		}
	}
	
	@Override
	public Date getCompleteDate() {
		assert complete;
		assert (completeDate != null);
		return completeDate;
	}
	
	public void setIsLastAdded(boolean isLastAdded) {
		this.lastAdded = isLastAdded;
	}
	
	public String getMemo() {
		return memo;
	}
	
	public void setMemo(String memo) {
		this.memo = memo;
	}
	
	public LinkedList<String> getTags() {
		return tags;
	}
	
	public void setTags(LinkedList<String> tags) {
		this.tags = tags;
	}
	
	public boolean equalsName(Task task) {
		return task != null &&
				(task.name == null) ? this.name == null : task.name.equals(this.name);
	}
}
